import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

Vue.config.productionTip = false

// 配置element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

// 配置vant
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);

// 配置axios
import axios from "@/utils/request"
Vue.prototype.$axios = axios;

// 全局路由导航守卫
router.beforeEach((to, from, next) => {
  next();
})

// 懒加载
import VueLazyload from 'vue-lazyload'
// 使用方法1:
Vue.use(VueLazyload)

// 配置echarts
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts;

// 全局路由导航守卫
router.beforeEach((to,from,next)=>{
	// 判断是否后台
	if(to.path.indexOf('/demo')>-1){
		// 判断是否登录页面
		if(to.path=="/demo/login"){
			if(store.state.token!=""){
				next('/demo/index')
			}
		}else{
			if(store.state.token==""){
				next('/demo/login')
			}
		}
		
		// 设置面包屑
		if(to.meta.hasOwnProperty('bread')){
			// 调用vuex中的方法
			store.commit('setBread',to.meta.bread)
		}else{
			store.commit('setBread',[])
		}
	}
	next();
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
